<?php
App::uses('AppModel', 'Model');
/**
 * Ciudade Model
 *
 * @property Paise $Paise
 * @property User $User
 */
class Ciudade extends AppModel {

public $validate=array(
    'nombre'=>array(
        'notEmpty'=>array(
            'rule'=>array('notEmpty'),
            'message'=>'El nombre es obligatorio'
        )
        ,'limitDuplicates'=>array(
          'rule'=>array('limitDuplicates',1),
            'message'=>'La ciudad ya existe'
        )
    )
);

public function limitDuplicates ($check, $limit){
    $existingPromoCount = $this->find('count',array(
       'conditions'=> $check,
        'recursive'=>-1
    ));
    return $existingPromoCount < $limit;
}

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'Paise' => array(
			'className' => 'Paise',
			'foreignKey' => 'ciudade_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'ciudade_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);

}
